﻿Module Managers
    Public ShaderManager As ContentManager(Of IShader)
    Public ObjectManager As ContentManager(Of Obje)
    Public BitmapManager As ContentManager(Of Bitmap)
    Public ModelManager As ContentManager(Of Model)
    Public Sub Initialize()
        ShaderManager = New ContentManager(Of IShader)
        ObjectManager = New ContentManager(Of Obje)
        BitmapManager = New ContentManager(Of Bitmap)
        ModelManager = New ContentManager(Of Model)
    End Sub
    Public Sub Clear()
        ShaderManager.Clear()
        ObjectManager.Clear()
        BitmapManager.Clear()
        ModelManager.Clear()
    End Sub
    Function ReturnShader(ByVal Index As Integer) As IShader
        If Index < 0 Then Return Nothing
        If ShaderManager.ItemExists(Index) Then
            Return ShaderManager.GetItem(Index)
        Else
            Dim nShader As IShader = Nothing
            Select Case magicMap.Library(Index).Xpe.FourCC
                Case "soso"
                    nShader = New ShaderModel(magicMap.Library(Index))
                Case "schi" ', "sotr"
                    nShader = New ShaderChicago(magicMap.Library(Index))
                Case "sotr"
                    nShader = New ShaderGeneric(magicMap.Library(Index))
                Case "senv"
                    nShader = New ShaderEnvironment(magicMap.Library(Index))
                Case "sgla"
                    nShader = New ShaderGlass(magicMap.Library(Index))
                Case "smet"
                    nShader = New ShaderMeter(magicMap.Library(Index))
                Case "swat"
                    nShader = New ShaderWater(magicMap.Library(Index))
            End Select
            If Not nShader Is Nothing Then
                ShaderManager.AddItem(Index, nShader)
            End If
            Return nShader
        End If
    End Function
    Function ReturnObject(ByVal Index As Integer) As Obje
        If Index < 0 Then Return Nothing
        If ObjectManager.ItemExists(Index) Then
            Return ObjectManager.GetItem(Index)
        Else
            Dim nObje As New Obje(magicMap.Library(Index))
            ObjectManager.AddItem(Index, nObje)
            Return nObje
        End If
    End Function
    Function ReturnBitmap(ByVal Index As Integer) As Bitmap
        If Index < 0 Then Return Nothing
        If BitmapManager.ItemExists(Index) Then
            Return BitmapManager.GetItem(Index)
        Else
            Dim nBitmap As New Bitmap(magicMap.Library(Index))
            BitmapManager.AddItem(Index, nBitmap)
            Return nBitmap
        End If
    End Function
    Function ReturnModel(ByVal Index As Integer) As Model
        If Index < 0 Then Return Nothing
        If ModelManager.ItemExists(Index) Then
            Return ModelManager.GetItem(Index)
        Else
            Dim nModel As New Model(magicMap.Library(Index))
            ModelManager.AddItem(Index, nModel)
            Return nModel
        End If
    End Function
End Module
